"""
    Esta clase sera la clase base para todas las entidades de negocio. 
"""
import cherrypy
import cjson
import EntidadDB

class EntidadNg:

    def __init__(self):
        self._entDB = None #Cada entidad de negocio tendra su correspondiente entidad de acceso a datos. 

#Region "Atributos"
    @apply
    def objetoDb():
        def fget(self):
            return self._entDB
        def fset(self):
            self._entDB = objetoDb
        return property(**locals())

    def index(self):
        # CherryPy will call this method for the root URI ("/") and send
        # its return value to the client. Because this is tutorial
        # lesson number 01, we'll just send something really simple.
        # How about...
        return "Hello vieja!"

    # Expose the index method through the web. CherryPy will never
    # publish methods that don't have the exposed attribute set to True.
    index.exposed = True

    def grabarSimple(self):
        return True
        """
            'agregarle que retorne algun tipo de error que se pueda llegara producir en los procesos que se van llamando en el medio
            Dim exito As Boolean
            Dim objDb As Object
            objDb = CrearInstanciaDb()
            exito = objDb.grabarSimple(aDescripcion)
            Return exito
        """

    def buscarSimple(self):
        return True 
        """
            Public Function buscarSimple(ByVal oTabla As DataTable, Optional ByVal texto As String = "") As Boolean
                Dim exito As Boolean
                Dim objDb As Object
                objDb = CrearInstanciaDb()
                exito = objDb.buscarSimple(oTabla, texto)
                Return exito
            End Function
        """
        """
            Public Function buscarTodos(ByRef dt As DataTable) As Boolean
                Dim exito As Boolean
                Dim objDb As Object
                objDb = CrearInstanciaDb()
                exito = objDb.buscarTodos(dt)
                Return exito
            End Function
        """
        """
            Public Overridable Function buscarTodosCompleto(ByRef dt As DataTable) As Boolean
                'Difiere del anterior en que recupera abslutamente toda la info de una entidad,
                'mientras que el metodo anterior solo recupera los campos id y descripcion.
                Dim exito As Boolean
                Dim objDb As Object
                objDb = CrearInstanciaDb()
                exito = objDb.buscarTodosCompleto(dt)
                Return exito
            End Function
        """
    def buscarPorId(self, id):
        a = EntidadDB.EntidadDB()
        a.campoid = 'id_persona'
        a.camposdescripcion = 'id_persona,apellido,nombre,id_tipodoc,documento,direccion,id_localidad,telefono,telefono_trabajo,celular,email'
        a.nombretabla = 'personas'
        a.buscarPorId(id)
        #objDb = eval(_entDB)
        #exito = objDb.buscarPorId(1)
        #if exito: dic = objDb.diccionario()
        #if exito: objJSON = a.diccionario.encode()
        objJSON = cjson.encode(a.diccionario)
        return objJSON
    buscarPorId.exposed = True 
       
cherrypy.quickstart(EntidadNg())
cherrypy.root = EntidadNg()  
cherrypy.server.start()  




"""
import os.path
tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')

if __name__ == '__main__':
    # CherryPy always starts with app.root when trying to map request URIs
    # to objects, so we need to mount a request handler root. A request
    # to '/' will be mapped to HelloWorld().index().
    cherrypy.quickstart(HelloWorld(), config=tutconf)
else:
    # This branch is for the test suite; you can ignore it.
    cherrypy.tree.mount(HelloWorld(), config=tutconf)

"""
"""
    Public Overridable Function borrar(ByRef pid As Long) As Boolean
        Dim exito As Boolean
        Dim objDb As Object
        objDb = CrearInstanciaDb()
        exito = objDb.borrar(pid)
        Return exito
    End Function

    Public Overridable Function CrearInstanciaDb()
        'Return New entidadDb
    End Function
End Class
"""